﻿
var personnelmanagement = angular.module("indexHome", ['vModal', 'Common', 'personnelLabel'])
 .factory('addUserFactory', function (vModal) {
     return vModal({
         controller: 'addUserModal',
         controllerAs: 'addUserFactory',
         templateUrl: '/system/views/personnel/newlyadded.html'
     });
 })

 .controller('indexHomeCtrl', ['$scope', '$http', '$rootScope', '$state', 'sysUserInfo', 'Restangular', 'Msg', 'T',function ($scope, $http, $rootScope, $state, sysUserInfo, Restangular, Msg,T) {
     $rootScope.secparstr = "";
     $scope.userid = sysUserInfo.getuserinfo().user_ID;
     $scope.orgid = sysUserInfo.getuserinfo().organization_ID;
     $scope.orgname = sysUserInfo.getuserinfo().user_Name + "(" + sysUserInfo.getuserinfo().organization_Name + ")"; //organization_Name; //     
     // 公告列表
     $http({
         url: $rootScope.requestUrl + '/Operate/findComeList?orgid=' + sysUserInfo.getuserinfo().organization_ID + '&powerLV=' + sysUserInfo.getuserinfo().powerLV,
         method: 'GET'
     }).success(function (response) {
         if (response.errorcode == "0") {
             $scope.otherList = response.datas;
         } else {
             Msg.error("获取失败！");
         }
     }).error(function () {
         console.log("连接服务器失败！");
     });
//     // 进行统计超级报表
//     $http({ method: 'POST', url: commonStatisticUrl + '/api', data: { orgid: sysUserInfo.getuserinfo().organization_ID, auto: 0} })
//     .success(function (res) {
//     });
     $scope.playFlag = false;
     $scope.playItem = "";
     // 预览
     $scope.play = function (item) {
         $scope.playItem = item;
         $scope.playFlag = true;
     }
     //关闭公告预览
     $scope.closePlay = function () {
         $scope.playFlag = false;
     }
     // 紧急任务加粗
     $scope.newStyle = function (item) {
         if (item) {
             return {
                 "color": "red",
                 "font-weight": "bold"
             };
         }
     }
     // 公告列表结束
     var linshishuzu = [];
     $scope.menufind = function (menus, panter) {
         if (menus != undefined && panter != undefined) {

             for (var i = 0; i < menus.length; i++) {
                 var menuobj = menus[i];
                 if (menuobj.name == panter) {
                     linshishuzu.push(menuobj);
                 } else {
                     if (menuobj.hasOwnProperty("childroute")) {
                         menuobj.childroute = angular.copy($scope.menufind(menuobj.childroute, panter));
                     }
                     //linshishuzu.push(menuobj);
                 }
             }

         }
         return linshishuzu;
     }

     //首页导航跳转页面
     $scope.playUrl = function (panter, params) {
         linshishuzu = [];
         //判断用户是否有对应页面的权限
         var muneflag = false;
         var mune = angular.copy($rootScope.rootscopeauthority);
         var abc = $scope.menufind(mune, panter);
         if (abc.length > 0) {
             muneflag = true;
         }

         if (muneflag) {
             if (params == 0 || params == 1 || params == 2 || params == 3) {
                 $state.go(panter, { id: params, routename: panter });

             } else {
                 $state.go(panter);
                 $rootScope.homeparams = params;
             }
         } else {
             Msg.warning("无权限访问！");
         }
     }

     var myChart = echarts.init(document.getElementById('main'));
     myChart.showLoading();
     var Ondata = "";
     Restangular.one("PersonnelSelector").customPOST({ name: "My Message" }, "GetLoginDateLog", { organization_ID: sysUserInfo.getuserinfo().organization_ID }).then(function (res) {
         if (res.errorcode == 0) {// 成功
             Ondata = res.datas;
             var dataAxis = new Array();
             var data = new Array();

             var yMax = 0;
             var dataShadow = [];
             Ondata.forEach(function (element, index) {
                 dataAxis.push(element.date_time);
                 data.push(element.login_size);
                 if (index == 0) {
                     yMax = element.login_size;
                 } else {
                     if (element.login_size > Ondata[index - 1].login_size) {
                         yMax = element.login_size;
                     }
                 }

             });
             for (var i = 0; i < data.length; i++) {
                 dataShadow.push(yMax);
             }
             myChart.hideLoading();
             myChart.setOption({
                 title: {
                     text: T.T("SystemUserLoginNumber"),
                     textAlign: 'left',
                     left: '38%',
                     top: '20px'

                     //subtext: 'Feature Sample: Gradient Color, Shadow, Click Zoom'
                 },
                 xAxis: {
                     data: dataAxis,
                     axisLabel: {
                         inside: false,
                         textStyle: {
                             color: '#000'
                         }
                     },
                     axisTick: {
                         show: false
                     },
                     axisLine: {
                         show: false
                     },
                     z: 10
                 },
                 yAxis: {
                     axisLine: {
                         show: false
                     },
                     axisTick: {
                         show: false
                     },
                     axisLabel: {
                         textStyle: {
                             color: '#999'
                         }
                     }
                 },
                 backgroundColor: { color: '#fff' },
                 dataZoom: [
		{
		    type: 'inside'
		}
		],
                 series: [
        { // For shadow
            type: 'bar',
            itemStyle: {
                normal: { color: 'rgba(0,0,0,0.05)' }
            },
            barGap: '-100%',
            barCategoryGap: '40%',
            data: dataShadow,
            animation: false
        },
        {
            type: 'bar',
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(
        				0, 0, 0, 1,
        				[
        				{ offset: 0, color: '#83bff6' },
        				{ offset: 0.5, color: '#188df0' },
        				{ offset: 1, color: '#188df0' }
        				]
        				)
                },
                emphasis: {
                    color: new echarts.graphic.LinearGradient(
        				0, 0, 0, 1,
        				[
        				{ offset: 0, color: '#2378f7' },
        				{ offset: 0.7, color: '#2378f7' },
        				{ offset: 1, color: '#83bff6' }
        				]
        				)
                }
            },
            data: data
        }
                ]
             });
             // Enable data zoom when user click bar.
             var zoomSize = 6;
             myChart.on('click', function (params) {
                 //                console.log(dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)]);
                 myChart.dispatchAction({
                     type: 'dataZoom',
                     startValue: dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)],
                     endValue: dataAxis[Math.min(params.dataIndex + zoomSize / 2, data.length - 1)]
                 });
             });
         }
     }, function callback() {
     });

     //     var alldata = { "data": null, "pageCount": null, "pageIndex": 1, "numCount": null, "datas": [{ "date_time": "2017-04-01", "login_size": "0" }, { "date_time": "2017-03-31", "login_size": "4" }, { "date_time": "2017-03-30", "login_size": "1" }, { "date_time": "2017-03-29", "login_size": "2" }, { "date_time": "2017-03-28", "login_size": "0" }, { "date_time": "2017-03-27", "login_size": "0" }, { "date_time": "2017-03-26", "login_size": "0"}], "errormsg": null, "pageSize": 20000, "errorcode": "0" }








 } ]);
